﻿using System.Linq;
using System.Windows.Shapes;

namespace DynamicGeometry
{
    public class ReflectedPoint : PointBase, IPoint
    {
        protected override Shape CreateShape()
        {
            return Factory.CreateDependentPointShape();
        }

        public override void Recalculate()
        {
            var source = Point(0);
            var mirror = this.Dependencies.ElementAt(1);
            IPoint mirrorPoint = mirror as IPoint;
            if (mirrorPoint != null)
            {
                Coordinates = Math.GetSymmetricPoint(source, mirrorPoint.Coordinates);
            }
            ILine mirrorLine = mirror as ILine;
            if (mirrorLine != null)
            {
                Coordinates = Math.GetSymmetricPoint(source, mirrorLine.Coordinates);
            }
            ICircle mirrorCircle = mirror as ICircle;
            if (mirrorCircle != null)
            {
                Coordinates = Math.GetSymmetricPoint(source, mirrorCircle.Center, mirrorCircle.Radius);
            }
            Exists = Coordinates.Exists();
        }
    }
}